﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using KenLib.BusinessManager;
using DataInfo;

public partial class Org_MasterPage : System.Web.UI.MasterPage
{
    本社情報Manager _本社情報Manager = new 本社情報Manager();
    基本情報Manager _基本情報Manager = new 基本情報Manager();
    public int index = 0;
    public int year = 0;
    string strDivsName = "div_input,div_frmO_TraineeInfoManager,div_frmO_TraineeList,div_frmO_TraineeBasicInfo,div_frmO_TraineeBasicInfo1,div_frmO_JointCompList,div_frmO_JointCompBasicInfoRef,div_frmO_JointCompBasicInfoRef1,div_frmO_JointCompBranchInfoRef,div_frmO_JointCompBranchInfoRef1,div_frmO_JointCompHistoryInfoRef,div_frmO_JointCompHistoryInfoRef1," + 
        "div_frmO_AppCompInfoManager,div_frmO_AppCompList,div_frmO_AppCompBasicInput,div_frmO_AppCompBasicCheck,div_frmO_AppCompBranchInput,div_frmO_AppCompBasicFinish,div_frmO_AppCompBranchInfo,div_frmO_AppCompBranchInfo1,div_frmO_AppCompHistoryInfo,div_frmO_AppCompHistoryInfo1,div_frmO_Manager,div_frmO_Manager1,div_frmO_BasicInfoRef,div_frmO_BasicInfoRef1,div_frmO_BranchInfo,div_frmO_CompBranchInfo1," + 
        "div_frmO_BranchInfo1,div_frmO_HistoryInfo,div_frmO_HistoryInfo1,div_frmO_AppCompBasicInfoRef1,div_frmO_EmpBasicInfoInput,div_frmO_EmpList,div_frmO_RequestReportCreate,"+
        "div_frmO_OtherReportCreate,div_frmO_EmpConditionList,div_frmO_TrainingInstitutionInput,div_frmO_TrainingSubjectSelect,div_frmO_TrainingList,div_frmO_TrainingPlanCreate,div_frmO_EmpConditionCreate,div_frmO_InspectReportTaskList,div_frmO_TraineeLifeReportTask,div_frmO_InspectReportTaskListt,div_frmO_HistoryInfoInput,div_frmO_EmpBasicInfoInput,div_frmO_EmpEnterInput,div_frmO_EmpContractTypeInput,div_frmO_EmpWorkSkillInput,div_frmO_EmpAcademicInput,div_frmO_EmpRewPunInput," +
        "div_frmO_EmpAcademicInput,div_frmO_EmpWorkedCompInput,div_frmO_BasicInfoInputCheck,div_frmO_EmpDegreeByCompInput,div_frmO_EmpDegreeByCompInput,div_frmO_EmpDivisionInput,div_frmO_EmpCareerInput,div_frmO_EmpDiplomaInput,div_frmO_BasicInfoInput,div_frmO_AppCompBasicInfoRef,div_frmO_EmpBasicInfo1,div_frmO_EmpBasicInfo";


    string strOperationMenu = "frmO_ContractSignSearch.aspx,frmO_ContractSignInsert.aspx,frmO_ContractSignCheck.aspx,frmO_ContractSignOutput.aspx,frmO_ContractSignDetail.aspx," +
        "frmO_AppCompSearch.aspx,frmO_AppCompInspectResult.aspx,frmO_AppCompInspectCheck.aspx,frmO_InspectReportRefSearch.aspx,frmO_InspectReportSelect.aspx,frmO_InspectReportCheck.aspx," +
        "frmO_InspectReportCreate.aspx";


    /// <summary>
    /// Coder: Dong
    /// Noi dung: Hien thi ten va quyen dang nhap len master pager
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void Page_Load(object sender, EventArgs e)
    {

        //if (Session["frmD_Login_user"] != null && Session["frmD_Login_user"].ToString() != "")
        //{
        //    if (Session["frmD_Login_user"].ToString() == "5")
        //    {
        //        lbl_User.Text = "Administrator";
        //        lbl_User.ForeColor = System.Drawing.Color.Yellow;
        //    }
        //    else if (Session["frmD_Login_user"].ToString() == "8")
        //    {
        //        DataTable dt1 = new DataTable();
        //        DataTable dt2 = new DataTable();
        //        if (Session["frmD_Login_企業コード"] != null && Session["frmD_Login_企業コード"].ToString() != "" && Session["frmD_Login_人コード"] != null && Session["frmD_Login_人コード"].ToString() != "")
        //        {
        //            dt1 = _本社情報Manager.frmD_UserLoginManager_Select企業ID_本社情報(Session["frmD_Login_企業コード"].ToString());
        //            dt2 = _基本情報Manager.frmD_Login_Get社員ID(Convert.ToInt32(dt1.Rows[0]["企業ID"]),Session["frmD_Login_人コード"].ToString());
        //            if (dt1.Rows.Count > 0 && dt2.Rows.Count > 0)
        //            {
        //                lbl_User.Text = ShowTextLength(dt2.Rows[0]["姓名"].ToString() + "・" + dt1.Rows[0]["企業名"].ToString());
        //                lbl_User.ToolTip = dt2.Rows[0]["姓名"].ToString() + "・" + dt1.Rows[0]["企業名"].ToString();
        //                lbl_User.ForeColor = System.Drawing.Color.Yellow;
        //            }
        //            else
        //            {
        //                Response.Redirect("../frmD_Login.aspx");
        //            }
        //        }
        //    }
        //    else if (Session["frmD_Login_user"].ToString() == "9")
        //    {
        //        DataTable dt1 = new DataTable();
        //        DataTable dt2 = new DataTable();
        //        if (Session["frmD_Login_企業コード"] != null && Session["frmD_Login_企業コード"].ToString() != "" && Session["frmD_Login_人コード"] != null && Session["frmD_Login_人コード"].ToString() != "")
        //        {
        //            dt1 = _本社情報Manager.frmD_UserLoginManager_Select企業ID_本社情報(Session["frmD_Login_企業コード"].ToString());
        //            dt2 = _基本情報Manager.frmD_Login_Get社員ID(Convert.ToInt32(dt1.Rows[0]["企業ID"]), Session["frmD_Login_人コード"].ToString());
        //            if (dt1.Rows.Count > 0 && dt2.Rows.Count > 0)
        //            {
        //                lbl_User.Text = ShowTextLength(dt2.Rows[0]["姓名"].ToString() + "・" + dt1.Rows[0]["企業名"].ToString());
        //                lbl_User.ToolTip = dt2.Rows[0]["姓名"].ToString() + "・" + dt1.Rows[0]["企業名"].ToString();
        //            }
        //            else
        //            {
        //                Response.Redirect("../frmD_Login.aspx");
        //            }
        //        }
        //    }
           
        //    else
        //    {
        //        Response.Redirect("../frmD_Login.aspx");
        //    }
        //}
        //else
        //{
        //    Response.Redirect("../frmD_Login.aspx");
        //}

        if (Session["frmD_Login_user"] != null && Session["frmD_Login_user"].ToString() != "")
        {
            if (Session["frmD_Login_user"].ToString() == "4")
            {
                if (Session["frmD_Login_企業コード"] != null && Session["frmD_Login_企業コード"].ToString() != "")
                {
                    DataTable dt1 = new DataTable();
                    dt1 = _本社情報Manager.frmD_UserLoginManager_Select企業ID_本社情報(Session["frmD_Login_企業コード"].ToString());
                    if (dt1.Rows.Count > 0)
                    {
                        lbl_User.Text = ShowTextLength(dt1.Rows[0]["企業名"].ToString());
                        lbl_User.ToolTip = dt1.Rows[0]["企業名"].ToString();
                    }
                    else
                    {
                        lbl_User.Text = "";
                    }
                }
                else
                {
                    Response.Redirect("frmD_Login.aspx");
                }
            }
            else if (Session["frmD_Login_user"].ToString() == "5")
            {
                lbl_User.Text = "Administrator";
                lbl_User.ForeColor = System.Drawing.Color.Yellow;
            }
            else if (Session["frmD_Login_user"].ToString() == "6")
            {
                DataTable dt1 = new DataTable();
                DataTable dt2 = new DataTable();
                if (Session["frmD_Login_企業コード"] != null && Session["frmD_Login_企業コード"].ToString() != "" && Session["frmD_Login_人コード"] != null && Session["frmD_Login_人コード"].ToString() != "")
                {
                    dt1 = _本社情報Manager.frmD_UserLoginManager_Select企業ID_本社情報(Session["frmD_Login_企業コード"].ToString());
                    dt2 = _基本情報Manager.frmD_Login_Get社員ID(Convert.ToInt32(dt1.Rows[0]["企業ID"]), Session["frmD_Login_人コード"].ToString());
                    if (dt1.Rows.Count > 0 && dt2.Rows.Count > 0)
                    {
                        lbl_User.Text = ShowTextLength(dt2.Rows[0]["姓名"].ToString() + "・" + dt1.Rows[0]["企業名"].ToString());
                        lbl_User.ToolTip = dt2.Rows[0]["姓名"].ToString() + "・" + dt1.Rows[0]["企業名"].ToString();
                        lbl_User.ForeColor = System.Drawing.Color.Yellow;
                    }
                    else
                    {
                        Response.Redirect("frmD_Login.aspx");
                    }
                }
            }
            else if (Session["frmD_Login_user"].ToString() == "7")
            {
                DataTable dt1 = new DataTable();
                DataTable dt2 = new DataTable();
                if (Session["frmD_Login_企業コード"] != null && Session["frmD_Login_企業コード"].ToString() != "" && Session["frmD_Login_人コード"] != null && Session["frmD_Login_人コード"].ToString() != "")
                {
                    dt1 = _本社情報Manager.frmD_UserLoginManager_Select企業ID_本社情報(Session["frmD_Login_企業コード"].ToString());
                    dt2 = _基本情報Manager.frmD_Login_Get社員ID(Convert.ToInt32(dt1.Rows[0]["企業ID"]), Session["frmD_Login_人コード"].ToString());
                    if (dt1.Rows.Count > 0 && dt2.Rows.Count > 0)
                    {
                        lbl_User.Text = ShowTextLength(dt2.Rows[0]["姓名"].ToString() + "・" + dt1.Rows[0]["企業名"].ToString());
                        lbl_User.ToolTip = dt2.Rows[0]["姓名"].ToString() + "・" + dt1.Rows[0]["企業名"].ToString();
                    }
                    else
                    {
                        Response.Redirect("frmD_Login.aspx");
                    }
                }
            }
            else if (Session["frmD_Login_user"].ToString() == "8")
            {
                DataTable dt1 = new DataTable();
                DataTable dt2 = new DataTable();
                if (Session["frmD_Login_企業コード"] != null && Session["frmD_Login_企業コード"].ToString() != "" && Session["frmD_Login_人コード"] != null && Session["frmD_Login_人コード"].ToString() != "")
                {
                    dt1 = _本社情報Manager.frmD_UserLoginManager_Select企業ID_本社情報(Session["frmD_Login_企業コード"].ToString());
                    dt2 = _基本情報Manager.frmD_Login_Get社員ID(Convert.ToInt32(dt1.Rows[0]["企業ID"]), Session["frmD_Login_人コード"].ToString());
                    if (dt1.Rows.Count > 0 && dt2.Rows.Count > 0)
                    {
                        lbl_User.Text = ShowTextLength(dt2.Rows[0]["姓名"].ToString() + "・" + dt1.Rows[0]["企業名"].ToString());
                        lbl_User.ToolTip = dt2.Rows[0]["姓名"].ToString() + "・" + dt1.Rows[0]["企業名"].ToString();
                        lbl_User.ForeColor = System.Drawing.Color.Yellow;
                    }
                    else
                    {
                        Response.Redirect("frmD_Login.aspx");
                    }
                }
            }
            else if (Session["frmD_Login_user"].ToString() == "9")
            {
                DataTable dt1 = new DataTable();
                DataTable dt2 = new DataTable();
                if (Session["frmD_Login_企業コード"] != null && Session["frmD_Login_企業コード"].ToString() != "" && Session["frmD_Login_人コード"] != null && Session["frmD_Login_人コード"].ToString() != "")
                {
                    dt1 = _本社情報Manager.frmD_UserLoginManager_Select企業ID_本社情報(Session["frmD_Login_企業コード"].ToString());
                    dt2 = _基本情報Manager.frmD_Login_Get社員ID(Convert.ToInt32(dt1.Rows[0]["企業ID"]), Session["frmD_Login_人コード"].ToString());
                    if (dt1.Rows.Count > 0 && dt2.Rows.Count > 0)
                    {
                        lbl_User.Text = ShowTextLength(dt2.Rows[0]["姓名"].ToString() + "・" + dt1.Rows[0]["企業名"].ToString());
                        lbl_User.ToolTip = dt2.Rows[0]["姓名"].ToString() + "・" + dt1.Rows[0]["企業名"].ToString();
                    }
                    else
                    {
                        Response.Redirect("frmD_Login.aspx");
                    }
                }
            }
            else
            {
                Response.Redirect("frmD_Login.aspx");
            }
        }
        else
        {
            //Response.Redirect("frmD_Login.aspx");
            lbl_User.Text = "";
        }
       
         #region luclt
        if (!IsPostBack)
        {
            if (Session["frmD_Login_user"] != null && Session["frmD_Login_user"].ToString() != "")
            {
                if (Session["frmD_Login_user"].ToString() == "9" || Session["frmD_Login_user"].ToString() == "8" || Session["frmD_Login_user"].ToString() == "5")
                {
                    frmO_AppCompBasicInfoRefManager mg = new frmO_AppCompBasicInfoRefManager();
                    int date = DateTime.Now.Year;
                    if (Request.QueryString["ComId"] != null && Request.QueryString["ComId"] != "")
                    {
                        int id = Int32.Parse(Request.QueryString["ComId"]);
                        for (int i = date; i >= (date) - 10; i--)
                        {
                            ddl_本社履歴情報.Items.Add(i.ToString() + " 年度");
                        }
                        DataTable tb = new DataTable();
                        tb = (DataTable)mg.get拠点名_frmO_AppCompBasicInfoRef(id);
                        if (tb.Rows.Count > 0)
                        {
                            ddl_実習実施場所情報.DataSource = tb;
                            ddl_実習実施場所情報.DataTextField = "拠点名";
                            ddl_実習実施場所情報.DataValueField = "拠点ID";
                            ddl_実習実施場所情報.DataBind();

                            ListItem 選択 = new ListItem("[選択]", "-1");
                            ddl_実習実施場所情報.Items.Insert(0, 選択);
                        }

                    }
                }
            }
            else
            {
                Response.Redirect("../frmD_Login.aspx");
            }
        }
            #endregion
        CheckLink();

#region Hunglt them thong bao loi confirm o link メインメニュー
        //hpl_メインメニュー.Attributes.Add("onclick", "if(confirm('" + GetError("CF00002") + "')== false) return false;");
#endregion
    }
    public void HideLiArea(string divShowName)
    {
        string[] str = strDivsName.Split(',');
        for (int i = 0; i < str.Length; i++)
        {
            Control c = aaa.FindControl(str[i]);
            if (c != null)
                c.Visible = false;
        }
        Control c1 = aaa.FindControl("div_" + divShowName);
        if (c1 != null)
            c1.Visible = true;
        Control c2 = aaa.FindControl("div_" + divShowName + "1");
        if (c2 != null)
            c2.Visible = true;

        if (strOperationMenu.Contains(Request.CurrentExecutionFilePath.Substring(Request.CurrentExecutionFilePath.LastIndexOf("/") + 1)))
        {
            hpl_メインメニュー.NavigateUrl = "frm_MOrgManager.aspx";
        }
      
    }

    /// <summary>
    /// Coder: Thanh Dong
    /// Function: Cut string when string too long
    /// </summary>
    /// <param name="temp"></param>
    /// <returns></returns>
    public string ShowTextLength(string temp)
    {

        if (checkContainsUnicodeCharacter(temp))
        {
            //true tieng nhat
            if (temp.Length > 50)
            {
                temp = temp.Substring(0, 50) + "...";
            }
        }
        else
        {
            //tieng viet
            if (temp.Length > 80)
            {
                temp = temp.Substring(0, 80) + "...";
            }
        }

        return temp;
    }

    /// <summary>
    /// Coder: Thanh Dong
    /// Function: Check byte string
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    public bool checkContainsUnicodeCharacter(string input)
    {
        const int MaxAnsiCode = 255;
        char[] a = input.ToCharArray();
        for (int i = 0; i < a.Length; i++)
        {
            if (a[i] > MaxAnsiCode)
            {
                return true;
            }
        }
        return false;
    }

    public void changeTitle(string value)
    {
        lbl_titleHeader.Text = value;
    }
    protected void lbtnLogout_Click(object sender, EventArgs e)
    {
        Session.Clear();
        Response.Redirect("~/frmD_Login.aspx");
    }
    public void CheckLink()
    {
        
        string sPath = System.Web.HttpContext.Current.Request.Url.AbsolutePath;
        System.IO.FileInfo oInfo = new System.IO.FileInfo(sPath); 
        string a=oInfo.Name;
        
        if (a.Equals("frmO_RequestReportCreate.aspx"))
        {
            HyperLink155.ForeColor = System.Drawing.Color.Red;
            
        }
        
          if (a.Equals("frmO_RequestReportCreate_1.aspx"))
        {
            HyperLink156.ForeColor = System.Drawing.Color.Red;
            
        }
        if (a.Equals("frmO_RequestReportCreate_2.aspx"))
        {
            HyperLink157.ForeColor = System.Drawing.Color.Red;

        }
        if (a.Equals("frmO_RequestReportCreate_3.aspx"))
        {
            HyperLink158.ForeColor = System.Drawing.Color.Red;

        }
        if (a.Equals("frmO_RequestReportCreate_4.aspx"))
        {
            HyperLink159.ForeColor = System.Drawing.Color.Red;

        }
        if (a.Equals("frmO_OtherReportCreate.aspx"))
        {
            HyperLink160.ForeColor = System.Drawing.Color.Red;

        }

        if (a.Equals("frmO_OtherReportCreate_1.aspx"))
        {
            HyperLink161.ForeColor = System.Drawing.Color.Red;

        }


    }
    #region Hunglt them ham lay ma loi
    public String GetError(string errorid)
    {
        string error = "";
        Error er = new Error();
        er.ErrorID = errorid;
        ErrorManager frm_error = new ErrorManager();
        DataTable dt = frm_error.getError(er);
        if (dt.Rows.Count > 0)
            error = dt.Rows[0][2].ToString();
        return error;
    }
    #endregion

    #region luclt
    protected void ddl_本社履歴情報_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (ddl_本社履歴情報.SelectedValue!="-1")
        {
            String mess = "この部分がまだ作成していません";
            string script = "<script type='text/javascript'>alert('" + mess + "');</script>";
            Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "alert", script);
        }
        
    }
    protected void ddl_実習実施場所情報_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (ddl_実習実施場所情報.SelectedValue!="-1")
        {
            String mess = "この部分がまだ作成していません";
            string script = "<script type='text/javascript'>alert('" + mess + "');</script>";
            Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "alert", script);
        }

    }
    #endregion
}
